package threat;

class Bank {
    private int account = 20000;//账号余额

    public synchronized boolean getMoney(int money) {
        int account = getAccount();
        if (account >= money) {
            account = account - money;
            Thread.yield();
            saveAccount(account);
            return true;
        }
        return false;
    }

    public void saveAccount(int account) {
        this.account = account;
    }

    //查询余额操作
    public int getAccount() {
        return account;
    }
}
